# -*- coding: utf-8 -*-
'''
Created on 2 sept. 2012

@author: Olivier
'''
import threading
from Data.TchatPlayer import TchatPlayer
from Data.Player import NewPlayer, PlayerList, ClickPlayer, MovePlayer,\
    UpdatePlayer

class ClientTreatment(threading.Thread):
    '''
    Thread use to treat the datas arrived from the server
    '''


    def __init__(self, inData, inClient):
        '''
        Constructor
        '''
        threading.Thread.__init__(self)
        print 'ClientTreatment INIT', inData
        self.__mData = inData
        self.__mClient = inClient
        
        self.start()

    def run(self):
        '''
        Function to do something with the received data
        '''
        if self.__mData == 'DisconnectOk':
            print 'DisconnectOk'
        elif self.__mData == 'InitYourself':
            self.__mClient.Send(NewPlayer(self.__mClient.GetController().GetPlayer()))
        elif type(self.__mData) == TchatPlayer:
            self.__mClient.GetController().WriteTchatPlayer(self.__mData)
        elif type(self.__mData) == PlayerList:
            self.__mClient.GetController().SetPlayerList(self.__mData.GetPlayerList())
        elif type(self.__mData) == ClickPlayer:
            self.__mClient.GetController().AddClickPlayer(self.__mData)
        elif type(self.__mData) == MovePlayer:
            self.__mClient.GetController().AddMovePlayer(self.__mData)
        elif type(self.__mData) == UpdatePlayer:
            self.__mClient.GetController().UpdatePlayer(self.__mData)
        else:
            print self.__mData
        
    